TDBCrossGrid Component

See Also          Properities          Methods          Events

TDBCrossGrid is a data aware component for displaying the multi-dimensions cross fields result for each single datasource.

Not all kinds of data can be used for doing crossing result. So user have to provide the reasonable data to TDBCrossGrid. All unreasonable data will get unexpected results.

TDBCrossGrid will link to a TDatasource by DataSource property in order to get the data source for doing the crossing result.

The major functionality are:

Display crossing result at both design time and run time.

Use drag and drop feature to switch the sequence order of cross fields at run time.

Use shrink and expand feature to see the data more clearly.

When a application uses TDBCrossGrid, at runtime, user can use the drag and drop


Quick Start of TDBCrossGrid

TCGridReport Component

Shrink and Expand of Cross field


TDBCrossGrid Component


Properties

Active	CGOptions	FPPrecision

AggrCaption	CrossSetup	LeftCol

AggrRowColumn	Cursor	Row

AggrSubCaption	DataSource	RowHeights

Align	DefaultColWidth	Serial

Col	DefaultRowHeight	TopRow

Color	FixedColor

ColWidths	Font

Confirm	FPDigits

Ctl3D	FPFormat


Methods

CellRect

ExpandAll

ExpandCell

ExpandColumn

ExpandRow

GetColCount

GetColField

GetColHeading

GetNumCrossCols

GetNumCrossRows

GetNumValueFields

GetRowCount

GetRowField

GetRowHeading

GetValField

GetValHeading

GetXCell

ReArrangeFields

Refresh

SetColHeading

SetRowHeading

ShrinkAll

ShrinkCell

ShrinkColumn

ShrinkRow


Events

OnClick

OnCFDataLoaded

OnDblClickXCell

OnDrawXCell

OnEnter

OnExit

OnLoaded

OnMouseDown

OnMouseMove

OnMouseUp

OnRowColumnChanged

OnSelectXCell


Shrink and Expansion of each cross field set

Shrink and Expansion of each cross field set.

Before each cross field value, a 'Plus' icon means this cross field can be expanded, a 'Minus' icon means this cross field had been expanded already. Use 'double click' to switch the states between 'Shrink' and 'Expand'.

The goCGShrinkExpand option in CGOptions can be turn off if user do allow the shrink and expansion for each cross field.

If goCGRowSizing or goCGColSizing option was set, each column width or row height can be different. In this case, shrink and expansion have to reset all column

widths and row heights, so user can feel the time delay of each shrink or expansion action. In order to increase the performance, turn off the goCGRowSizing and goCGColSizing are recommended.


Quick Start of TDBCrossGrid Component

Do the following steps and check the result.

Step 1: Copy ectsales.db(included in the whole package) to desired place, DBDEMOS are recommended.

Step 2: Get a TQuery(Query1), TDataSource(DataSource1) and TDBCrossGrid(DBCrossGrid1) component in your form.

Step 3: Set Query1.DatabaseName to a database 'DBDEMOS'.

Step 4: Set Query1.SQL property to 'select syear,squarter,sum(amount) from ectsales group by syear,squarter'.

Step 5: Set the Query1.Active property to 'TRUE'.

Step 6: Set the DataSource1.DataSet property to Query1.

Step 7: Set the DBCrossGrid1.DataSource to DataSource1.

Step 8: Set the DBCrossGrid1.Active to 'TRUE'.

Now, you should see the results. Run the program, and use drag and drop to switch the cross column fields and cross row fields, different crossing results will be shown.


TCGridReport Component

See Also          Properities          Methods          Events

TCGridReport component is the easiest way to print out a cross table report. Use the TCGridReport to link to TDBCrossGrid and call the Print method to print the cross table result to printer.


Properties

BottomMargin

CrossSource

FooterText

FooterAligment

FooterFont

FooterLogo

FooterLogoPos

FooterLogoWidth

HeaderAligment

HeaderFont

HeaderLogo

HeaderLogoPos

HeaderLogoWidth

HeaderText

LeftMargin

LineStyle

RightMargin

TopMargin


Methods

CreateASCII

CreateHTML

Print

Preset

Preview


Events

OnPrintXCell


See TStringGrid Component.


See TDatabase Component for more details.


See TTable Component for more details.


Active Property

Boolean Field.

When active property is set to true, TDBCrossGrid will access data from DataSource and put the results into the grid. When active property is set to false, the grid will be reset to empty.


AggrCaption Property

String Field.

AggrCaption property string will be used for aggregated row heading and aggregated

column heading


AggrRowColumn Property

Boolean Field

AggrRowCoumn can be turned True of False. When it was turned True, aggregation function and sub-aggregation function will be performed otherwise no aggregation function will be applied to cross results.

Once the AggrRowColumn was turned off, the goCGShrinkExpand option in CGOptions will be removed. If user try to add goCGShrinkExpand option back into CGOptions, AggrRowColumn have to be turn True first.


AggrSubCaption Property

String Field.

AggrSubCaption property string will be used for sub-aggregated row heading and sub- aggregated column heading .


Serial Property

Confirm Property

Serial Property

String Field.

When you register the TDBCrossGrid component, you will get a set of Serial and Confirm number. If these two fields do not have the right information, the TDBCrossGrid will not work during the run time. Testing set of Serial and Confirm number always available by sending a email to pathcorp@use.usit.net


CrossSetup Property

String List Field.

The CrossSetup property is a list of strings . The CrossSetup include three parts, cross column fields, cross row fields and value fields. Once TDBCrossGrid was linked to a active DataSource, CrossSetup have been set as default value. The TDBCrossGrid provides a property editor for CrossSetup. User can use the property editor to re-arrange the order sequence of cross fields. The corresponding heading for each field can be changed in the property editor also. Cross column fields are used as fixed columns, cross row fields are used as fixed rows and value fields are used as cross results.


CGOptions Property

Set of (goCGAutoColWidth, goCGColSizing, goCGHeadings, goCGHorzLine, goCGRowSizing, goCGRunTimeDragging, goCGShrinkExpand, goCGVertLine)

Description

goCGAutoColWidth:

If True,All column widths will be adjusted to fit the longest cell.

goCGColSizing:

If True, each column will be allowed to be resized during run time.

goCGHeadings:

If True, the headings for all cross column fields, cross row fields 	and value field will be visible.

goCGHorzLine:

If True, all horizon lines will be visible.

goCGRowSizing:

If True, each row will  allow resizing during run tim.

goCGRunTimeDragging:

If True, run-time dragging will be allowed.

goCGShrinkExpand:

If True, run-time expand and shrink cross fields will be allowed.

goCGVertLine:

If True, all vertical lines will be visible.


DataSource Property

See TDBGrid Component for more details


FPDigits Property

Integer Field.

Please see FPFormat for more details.


FPFormat Property

Set of (ffGeneral,ffExponent,ffFixed,ffNumber,ffCurency).

All Cells will be displayed as floating value. The format will depend on FPDigits, FPFormat and FPPrecision properties. For more details, please see FloatToStrF.


FPPrecision Property

Integer Field.

Please see FPFormat for more details.


NullCaption Property

String Field.

The NullCaption property is used for displaying null cells. The default value for NullCaption is empty. User can assign a special string to NullCaption, all null cells will

then be shown with NullCaption value.


Margin Property

LeftMargin,RightMargin,TopMargin,BottomMargin Properties

Integer Fields.

LeftMargin:	Offset from the left edge of a paper.

RightMargin:	Offset from the right edge of a paper.

TopMargin:	Offset from the top edge of a paper.

BottomMargin:	Offset from the bottom edge of a paper.


Header Properties

HeaderAligment,HeaderFont,HeaderText Properties

HeaderAligment:	TAligment.

HeaderFont:	TFont.

HeaderText:	TStringFields, Text string will be used as Header.


HeaderLogo Properties

HeaderLogo,HeaderLogoPos,HeaderLogoWidth Properties

HeaderLogo:	TImage. Pointer to any Timage component.

HeaderLogoPos:	TLogoPosition = (lpBeforeText, lpAfterText)

lpBeforeText : Place the image before the text.

LpAfterText:  Place the image after the text.

HeaderLogoWidth:	Integer. Width of the space to place the Logo .


Footers Properties

FooterAligment,FooterFont,FooterText Properties

FooterAligment:	TAligment.

FooterFont:	TFont.

FooterText:	TStringFields, Text string will be used as Footer.


FooterLogo Properties

FooterLogo, FooterLogoPos, FooterLogoWidth Properties

FooterLogo:	TImage. Pointer to any Timage component.

FooterLogoPos:	TLogoPosition = (lpBeforeText, lpAfterText)

lpBeforeText : Place the image before the text.

LpAfterText:  Place the image after the text.

FooterLogoWidth:	Integer. Width of the space to place the Logo .


CrossSource Properties

CrossSource Property

CrossSource will be link to a TDBCrossGrid which will be used to generate a report.


LineStyle Properties

LineStyle Property

LineStyle : TPenStyle. Each cross value line will use this LineStyle property to draw the line. If goCGVertLine is set to true in CrossSource.CGOptions, the vertical line willl be drawn. If goCGHornLine is set to true in CrossSource.CGOptions, the horizontal line will be drawn.


Print,Preview,Preset Methods

Print,Preset,Preview Methods

Declaration

Procedure Print;

Procedure Preset;

Procedure Preview;

Description

For Delphi 1.0, Print method will send a report to Printer.

For Delphi2.0, Preset method will generate a temporary report, use Preview method to preview the temporary report, and use Print method to send the temporary report to printer.

Here is a quick review of how to use TCGridReport

For Delphi1.0

Add a TDBCrossGrid call DBCrossGrid1 to your form.

Add a TCGridReport call CGridReport1 to your form.

Add a TButton call 'Print' to your form.

Setup DBCrossGrid1 as before.

Setup CGridReport1.CrossSource to DBCrossGrid1.

Setup 'Print'.onclick() as

CGridReport1.Print;

For Delphi2.0

Add a TDBCrossGrid call DBCrossGrid1 to your form.

Add a TCGridReport call CGridReport1 to your form.

Add a TButton call 'Preview' to your form.

Add a TButton call 'Print' to your form.

Setup DBCrossGrid1 as before.

Setup CGridReport1.CrossSource to DBCrossGrid1.

Setup 'Preview'.onclick() as

CrossReport1.Preset;

CrossReport1.Preview;

Setup 'Print'.onclick() as

CrossReport1.Preset;

CrossReport1.Print;


ExpandAll Method

Declaration

procedure ExpandAll;

Description

All cross-rows/cross-columns will be fully expanded.


ExpandCell Method

Declaration

procedure ExpandCell(ACol,Arow : Longint);

Description

If the cell(ACol,Arow) is expandable, it means this cell data will be leaded by a '+' sign. This method will work exactly same as double click the cell with '+' sign..


ExpandColumn Method

ExpanColumn Method

Declaration

procedure ExpandColumn(ACol : Longint);

Description

All the cells in ACol-th fixed column will be expanded. The fixed column index start with 0.


ExpandRow Method

ExpanRow Method

Declaration

procedure ExpandRow(ARow : Longint);

Description

All the cells in ARow-th fixed row will be expanded. The fixed row index start with 0.


GetColCount Method

Declaration

function GetColCount: Longint;

Description

Return the total number of columns of TDBCrossGrid.


GetColField Method

Declaration

function GetColField(Const index : LoingInt): String;

Description

Return the column cross field specified by index .

Index 0 will return first column cross field.


GetColHeading Method

Declaration

function GetColHeading(Const index : LoingInt): String;

Description

Return the cross column's heading specified by index .

Index 0 will return first cross column's heading.


GetNumCrossCols Method

Declaration

function GetNumCrossCols: Longint;

Description

Return the total number of cross columns(column cross fields) of TDBCrossGrid


GetNumCrossRows Method

Declaration

function GetNumCrossRows: Longint;

Description

Return the total numbers of cross rows(row cross fields) of TDBCrossGrid


GetNumValueFields Method

Declaration

function GetNumValueFields: Longint;

Description

Return the total numbers of aggregate value fields of TDBCrossGrid.


GetRowCount Method

Declaration

function GetRowCount: Longint;

Description

Return the total number of rows of TDBCrossGrid.


GetRowField Method

Declaration

function GetRowField(Const index : Longing): String;

Description

Return the cross row field specified by index .

Index 0 will return first cross row field.


GetRowHeading Method

Declaration

function GetRowHeading(Const index : Longing): String;

Description

Return the cross row's heading specified by index .

Index 0 will return first cross row's heading.


GetValField Method

Declaration

function GetValField(Const index : Longing): String;

Description

Return the value field specified by index .

Index 0 will return first value field.


GetValHeading Method

Declaration

function GetValHeading(Const index : Longing): String;

Description

Return the value heading specified by index .

Index 0 will return first value heading.


GetXCell Method

Declaration

function GetXCell(Const ACol,ARow : Longing): String;

Description

Return the cell string value of TDBCrossGrid specified by ACol and ARow

ACol: Column index.

ARow: Row index. .


ReArrangeFields Method

Declaration

procedure ReArrangeFields(NCCol,NCRow,NVal : Longint; AggrList : TStrings);

Description

ReArrangeFields allow the user to re-arrange the number of fields were used for column, row or value.

NCCol :	Number of fields will be used as cross columns.

NCRow:	Number of fields will be used as cross rows.

Nval:	Number of fields will be used as value fields.

AggrList:	List of all aggregation functions. If AggrRowColumn property was set to 'FALSE', this parameter will not be used. The legal value of aggregation function are sum,avg,min,max and count.


ReFresh Method

Declaration

Function ReFresh : Boolean;

Description

When ReFresh method is called. TDBCrossGrid will re-access the database and get a new set of data. If error happens, 'False' will be returned


SetColHeading Method

Declaration

procedure SetColHeading(Const cindex : Longint; Value : String);

Description

Set the cross column heading to 'Value' specified by 'cindex'.

'cindex' 0 will set first cross column's heading.


SetRowHeading Method

Declaration

procedure SetRowHeading(Const rindex : Longint; Value : String);

Description

Set the cross row heading to 'Value' specified by 'rindex'.

'rindex' 0 will set first cross row's heading.


ShrinkAll Method

Declaration

procedure ShrinkAll;

Description

All cross-rows/cross-columns will be fully shrank.


ShrinkCell Method

Declaration

procedure ShrinkCell(ACol,Arow : Longint);

Description

If the cell(ACol,Arow) is shrinkable, it means this cell data will be leaded by a '-' sign. This method will work exactly same as double click the cell with '-' sign..


ShrinkColumn Method

Declaration

procedure ShrinkColumn(ACol : Longint);

Description

All the cells in ACol-th fixed column will be shrank. The fixed column index start with 0.


ShrinkRow Method

Declaration

procedure ShrinkRow(ARow : Longint);

Description

All the cells in ARow-th fixed row will be shrank. The fixed row index start with 0.


CreateASCII Method

Declaration

procedure CreateASCII(filename : string; sep : string);

Description

CreateASCII method will create a ASCII text file of cross table from CrossSource. The filename is the file name which where the ASCII file will be put out. The 'sep' is the field separator which will be used to separate data fields.


CreateHTML Method

Declaration

procedure CreateHTML(filename : string);

Description

CreateHTML method will create a HTML format file of cross table from CrossSource. The filename is the file name which where the HTML file will be put out. The HTML file is a ascii text file, so it can be modified by the user to make it more customized.


OnCFDataLoaded Event

Declaration

property OnCFDataLoaded: TCFDataLoadedEvent;

TCFDataLoadedEvent  =  procedure (Sender : Tobject; Index : Integer; var Vals : Tstrings) of object;

Description

OnCFDataLoaded event will be generated after the values of cross-row/cross-column had been retrieved from underline database.All the values of each cross-row/cross-column are sorted by their ASCII value. Sometime, user are welling to see different sequence value of cross-row/cross-column, user can use this event

to re-arrange the sequence of cross-row/cross-column.

Index: index number of cross-row/cross-column. E.g. if you have 2 cross-row and 1 cross-column, Index 0 will be the first cross-column, 1 will be first cross-row, 2 will be second cross-row.

Vals: This is a string list, list all the values of cross-row or cross-column pointer by

the Index field. User can re-arrange the sequences of this list.


OnSelectXCell Event

Declaration

property OnSelectXCell: TSelectXCellEvent;

TSelectXCellEvent  =  procedure (Sender : Tobject; Col, Row : Longint) of object;

Description

The OnSelectXCell event occurs when the user selects a cell in a TDBCrossGrid. Use the OnSelectXCell event handler to write the code that handles the selecting of a cell.


OnDblClickXCell Event

Declaration

property OnDblClickXCell: TSelectXCellEvent;

TSelectXCellEvent  =  procedure (Sender : Tobject; Col, Row : Longint) of object;

Description

The OnDblClickXCell event occurs when the user double clicks a cell in a TDBCrossGrid. Use the OnDblClickXCell event handler to write the code that handles the selecting of a cell. When the user double clicks a cell, the OnSelectXCell event is generated also.


OnDrawXCell Event

Declaration

property OnDrawXCell: TDrawCellEvent;

Description

The OnDrawXCell event occurs after each cell is drawn in a TDBCrossGrid Use the OnDrawXCell event handler to customize cells.


OnLoaded Event

Declaration

property OnLoaded: TNotifyEvent;

Description

The OnLoaded event occurs after the TDBCrossGrid is loaded in run time . Use the OnLoaded event handler to write the code that handles the extra things you need to do after the TDBCrossGrid is loaded.


OnRowColumnChanged Event

Declaration

property OnRowColumnChanged: TNotifyEvent;

Description

The OnRowColumnChanged event occurs after the user to use drag and drop feature to switch the cross row fields and cross column fields of TDBCrossGrid .


OnPrintXCell Event

Declaration

property OnPrintXCell: TPrintXCellEvent;

TPrintXCellEvent  =  procedure (Sender : Tobject; Col, Row : Longint; var XCell : string) of object;

Description

The OnPrintXCell event occurs before each cell of CrossSource will be printed. User can send a new string value to TCGridReport to replace the default cell value.

Col :	The column of current printed cell.

Row: 	The row of current printed cell.

XCell:	This value will be sent back to TCGridReport and will be used as printed value.


See all components.